package appbuilder.application;

import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;

/**
 * @author Bruno Gama Catão
 * @since 2007-12-28
 */
public class Context {
    private static Logger logger = Logger.getLogger(Context.class.getName());
    
    private static Context instance;
    private VelocityContext context;
    
    public static Context getInstance() {
        if (instance == null) {
            try {
                instance = new Context();
            } catch (Exception ex) {
                logger.log(Level.SEVERE, null, ex);
            }
        }
        
        return instance;
    }
    
    private Context() throws Exception {
        initVelocity();
    }
    
    public VelocityContext getContext() {
        return context;
    }
    
    private void initVelocity() throws Exception {
        logger.info("initializing the template engine");
        Velocity.init();
        context = new VelocityContext();
    }
}
